package cn.edu.uestc.cwdsj.service;


import cn.edu.uestc.cwdsj.utils.constant.RoleConstants;
import cn.edu.uestc.framework.auth.annotation.TKRoleRequired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.io.Serializable;

import java.text.DecimalFormat;
import java.util.List;

@Service
@Transactional
public class Testgechengfenbilichaxun implements Serializable{
    @Resource
    private Testreal re;
    @TKRoleRequired(roleId = RoleConstants.ROLE_ANY)
    public String[] getgecheng(){
        List<Real> te=re.getRealList();
        double[] count=new double[3];
        String[] bili=new String[3];
        for(int i=0;i<=2;i++){
            count[i]=0.0;
        }
        for(Real i : te){
            if((i.getOtherunit()!=null)&&(i.getYichangyufou().equals("正常"))){
                count[0]=count[0]+1.0;
            }
            else if((i.getOtherunit()!=null)&&(i.getYichangyufou().equals("异常"))){
                count[1]=count[1]+1.0;
            }
            else if((i.getOtherunit()!=null)&&(i.getYichangyufou().equals("疑似异常"))){
                count[2]=count[2]+1.0;
            }
        }
        double sum=count[0]+count[1]+count[2];
        for(int i=0;i<=1;i++){
            count[i]=count[i]/sum*100.0;
            DecimalFormat df = new DecimalFormat("#.0");
            bili[i]=df.format(count[i]);
        }
        Double tem=100.0-Double.valueOf(bili[0])-Double.valueOf(bili[1]);
        DecimalFormat df = new DecimalFormat("#.0");
        bili[2]=df.format(tem);
        return bili;
    }






}
